package com.zkingsoft.laqeelin.action;

import static com.zkingsoft.common.constance.AppConstance.SAFEPATH;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.matrix.core.anotations.RemoveRequestToken;
import com.matrix.core.anotations.SaveRequestToken;
import com.matrix.core.constance.SystemErrorCode;
import com.matrix.core.constance.SystemMessageCode;
import com.matrix.core.exception.GlobleException;
import com.matrix.core.pojo.AjaxResult;
import com.matrix.core.pojo.PaginationVO;
import com.matrix.core.tools.WebUtil;
import com.matrix.core.web.BaseAction;
import com.zkingsoft.laqeelin.bean.BizHelpActivity;
import com.zkingsoft.laqeelin.bean.BizOrder;
import com.zkingsoft.laqeelin.service.BizOrderService;

/**
 * @description (订单表)
 * @author 何明
 * @date 2018-09-01 10:35
 */
@Controller
@RequestMapping(value = "admin/bizOrder")
public class BizOrderAction extends BaseAction{

	@Autowired
	private BizOrderService bizOrderService;
	
	//记录编辑前的值Before_Edit_Value
	public static final String BEV="BizOrder_BEV";
	
	
	/**
	 * 列表显示
	 */
	@RequestMapping(value = "/showList")
	public @ResponseBody AjaxResult showList(BizOrder bizOrder, PaginationVO pageVo) {
		return showList(bizOrderService, bizOrder, pageVo);
	}
   	
	/**
	 * 新增
	 */   
	@RemoveRequestToken	
   	@RequestMapping(value =  "/addBizOrder")
	public @ResponseBody AjaxResult addBizOrder(BizOrder bizOrder) {
	 	int i=bizOrderService.add(bizOrder);
	 	if(i > 0){
	 		return new AjaxResult(AjaxResult.STATUS_SUCCESS, SystemMessageCode.ADD_SUCCES, "(订单表)");
	 	}else {
			throw new GlobleException(SystemErrorCode.DATA_ADD_FAIL);
		}
	}
	
	
	
	
	
	/**
	 * 修改
	 */   
	@RemoveRequestToken	
   	@RequestMapping(value =  "/modifyBizOrder")
	public @ResponseBody AjaxResult modifyBizOrder(BizOrder bizOrder) {
	   		bizOrder.setOrderId(((BizOrder)WebUtil.getSessionAttribute(BEV)).getOrderId());
	   		AjaxResult result=modify(bizOrderService, WebUtil.getSessionAttribute(BEV), bizOrder, "(订单表)");
			WebUtil.removeSessionAttribute(BEV);
			return  result;
	}
	
	
	
	
   	/**
	 * 进入修改界面
	 */   
	@SaveRequestToken
   	@RequestMapping(value =  "/editForm")
	public String editForm(String id) {
		BizOrder bizOrder;
		if (id != null) {
			bizOrder = bizOrderService.findById(id);
			WebUtil.getRequest().setAttribute("obj", bizOrder);
			WebUtil.setSessionAttribute(BEV, bizOrder);
		}
		return "admin/BizOrder-form";
	}
   	
   	
   	/**
	 * 删除
	 */  
 	@RequestMapping(value = "/del")
	public @ResponseBody AjaxResult del(String keys) {
		return remove(bizOrderService, keys);
	}
  
	/**
	 * 消费
	 */  
 	@RequestMapping(value = "/consumer")
	public @ResponseBody AjaxResult consumer (BizOrder order) {
 		BizOrder bizOrder=new BizOrder();
 		bizOrder.setOrderId(order.getOrderId());
 		bizOrder.setOrderStatus(2);
 		int i =bizOrderService.modifyByModel(bizOrder);
 		if(i==0){
 			return new AjaxResult(AjaxResult.STATUS_FAIL,"操作失败");
 		}
 		return new AjaxResult(AjaxResult.STATUS_SUCCESS,"操作成功");
	}
 	
}